<%@tag pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@attribute name="page" required="true" type="cn.livingCloud.dto.Page" %>
<c:set var="first" value="${page.first}"/>
<c:set var="last" value="${page.last}"/>
<c:if test="${not empty page.list}">
    <div class="dataTables_info small" id="table2_info" role="status"
         aria-live="polite">共${page.totalPage}页,${page.totalRecord}条数据
    </div>
    <div class="dataTables_paginate paging_simple_numbers" id="table1_paginate">
        <div style="display: inline-block;margin-right:5px;" class="pull-left">
            每页
            <input type="number" value="${page.rowSize}" class="paginate_button form-control RowSize"
                   aria-controls="table1"
                   tabindex="0" style="display:inline-block;width:75px;height:35px;line-height:15px;margin-right:5px;"
                   min="1"/>条数据
            跳转到
            <input type="number" value="${page.currentPage}" class="paginate_button form-control currentPage"
                   aria-controls="table1"
                   tabindex="0" style="display:inline-block;width:55px;height:35px;line-height:15px;margin-right:5px;"
                   min="1"/>页
        </div>
        <c:if test="${not first}">
            <a class="paginate_button previous disabled" aria-controls="table1" data-dt-idx="0"
               tabindex="0" id="table1_previous" href="javascript:toPage(${page.currentPage-1})">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </c:if>
        <span>
        <c:forEach begin="${page.beginPageNumber}" end="${page.endPageNumber}" var="index">
            <a class="paginate_button ${index eq page.currentPage?"current":""}" href="javascript:toPage(${index})"
               aria-controls="table1" data-dt-idx="1" tabindex="0">${index}</a>
        </c:forEach>
            </span>
        <c:if test="${not last}">
            <a class="paginate_button next" aria-controls="table1" tabindex="0" id="table1_next"
               href="javascript:toPage(${page.currentPage+1})"><span aria-hidden="true">&raquo;</span></a>
        </c:if>
    </div>

    <script type="text/javascript">
        function changeURLArg(url, arg, arg_val) {
            var pattern = arg + '=([^&]*)';
            var replaceText = arg + '=' + arg_val;
            if (url.match(pattern)) {
                var tmp = '/(' + arg + '=)([^&]*)/gi';
                tmp = url.replace(eval(tmp), replaceText);
                return tmp;
            } else {
                if (url.match('[\?]')) {
                    return url + '&' + replaceText;
                } else {
                    return url + '?' + replaceText;
                }
            }
            return url + '\n' + arg + '\n' + arg_val;
        }

        function toPage(pageNumber) {
            var url = this.location.href.toString();
            var arg = changeURLArg(url, "currentPage", pageNumber);
            this.location.href = arg;
        }

        $(".RowSize").change(function () {
            var changeURLArg2 = changeURLArg(window.location.href.toString(), "rowSize", $(this).val());
            window.location.href = changeURLArg2;
        });

        $(".currentPage").change(function () {
            var changeURLArg2 = changeURLArg(window.location.href.toString(), "currentPage", $(this).val());
            window.location.href = changeURLArg2;
        });
    </script>
</c:if>